import "./admin.less";

import {message} from "antd"

import React from "react";
import { Redirect, Route, Switch } from "react-router-dom";

// 导入二级路由
import CateGory from "../Category/Category";
import Bar from "../chars/bar";
import Line from "../chars/line";
import Pie from "../chars/pie";
import Home from "../home/home";
import Product from "../product/product";
import Role from "../role/role";
import User from "../user/user";


// 导入相关组件
import AdminHeader from "../../components/admin/AdminHeader";
import AdminLeft from "../../components/admin/AdminLeft";

// 后台管理的home页
export default class Admin extends React.Component {
  constructor(props) {
    super(props);
  }
  goLogin = () => {
    this.props.history.push("/login");
  };
  componentDidMount() {
    // 测试redux  先关闭
    // let userdata = sessionStorage.getItem("userdata");
    // if (!userdata) {
    //   message.error("请先登陆");
    //   return this.goLogin();
    // }
  }

  render() {
    return (
      <div className="admin">
        <div className="admin-left">
          <AdminLeft />
        </div>
        <div className="admin-right">
          <div className="admin-header">
            <AdminHeader />
          </div>
          <div className="admin-content">
            {/* 这是二级路由 */}
            <Switch>
              <Route path="/cateGory" exact component={CateGory}></Route>
              <Route path="/chars/bar" exact component={Bar}></Route>
              <Route path="/chars/Line" exact component={Line}></Route>
              <Route path="/chars/pie" exact component={Pie}></Route>
              <Route path="/home" exact component={Home}></Route>
              <Route path="/product" exact component={Product}></Route>
              <Route path="/role" exact component={Role}></Route>
              <Route path="/user" exact component={User}></Route>
              {/* 以上都不匹配成功，就会执行 */}
              <Redirect to="/home"></Redirect>      
            </Switch>
          </div>
          <div className="admin-footer">
            <p>我是底部数据，使用谷歌打开体验更佳</p>
          </div>
        </div>
      </div>
    );
  }
}
